//**************************************************************************************************************
// CLASS: InstrTypeRI
//
// DESCRIPTION
// See comments in InstrTypeRI.hpp.
//
// AUTHOR INFORMATION
// Kevin R. Burger [KRB]
//   
// Mailing Address:
// Computer Science & Engineering
// School of Computing, Informatics, and Decision Systems Engineering
// Arizona State University
// Tempe, AZ 85287-8809
//
// Email: burgerk@asu
// Web:   http://kevin.floorsoup.com
//**************************************************************************************************************
#include "InstrTypeRI.hpp"

//==============================================================================================================
// PUBLIC FUNCTION MEMBERS
//==============================================================================================================

//--------------------------------------------------------------------------------------------------------------
// Default ctor.
//
// DESCRIPTION:
// Does nothing.
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::InstrTypeRI()
{
}

//--------------------------------------------------------------------------------------------------------------
// Another ctor.
//
// DESCRIPTION:
// Call the base class InstrTypeR::InstrTypeR(string const&, Register const&) ctor to let it initialize the
// mMnemonic and mRegister data members that were inherited from Instr and InstrTypeR. Then initialize mInteger
// to pInteger (either in the ctor body or the member init list).
//--------------------------------------------------------------------------------------------------------------
InstrTypeRV::InstrTypeRV
    (
    std::string const& pMnemonic,
    Register const&    pRegister,
    Variable const&    pVariable
    )
    :
    InstrTypeR(pMnemonic, pRegister),
    mInteger(pInteger)
{
}

//--------------------------------------------------------------------------------------------------------------
// Copy ctor.
//
// DESCRIPTION:
// Calls Copy() and passess pInstr to make this object a copy of pInstr.
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::InstrTypeRI
    (
    InstrTypeRV const& pInstr
    )
{
    Copy(pInstr);
}

//--------------------------------------------------------------------------------------------------------------
// Dtor.
//
// DESCRIPTION:
// Does nothing.
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::~InstrTypeRI()
{
}

//--------------------------------------------------------------------------------------------------------------
// Encode()
//
// DESCRIPTION:
// When an InstrTypeRI is encoded, we first call the base class InstrTypeR::Encode() function to allow it to
// place the register bit in position 26 (note that InstrTypeR::Encode() calls Instr::Encode() to allow that
// function to encode the opcode bits). Then we place the integer bits into the encoding.
//
// PSEUDOCODE:
// Call InstrTypeR::Encode()
// Put the immediate into the proper bit positions of mEncoding.
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::Encode()
{
    Instr::Encode();
}

//--------------------------------------------------------------------------------------------------------------
// GetInteger()
//
// DESCRIPTION:
// mInteger accessor function.
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::GetInteger() const
{
    return mInteger;
}

//--------------------------------------------------------------------------------------------------------------
// operator=()
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI& operator=(InstrTypeRI const& pInstr)
{
    if (this != &pInstr) 
        Copy(pInstr);
    return *this;
}

//==============================================================================================================
// PROTECTED FUNCTION MEMBERS
//==============================================================================================================

//--------------------------------------------------------------------------------------------------------------
// Copy()
//
// DESCRIPTION:
// Makes this InstrTypeRI a copy of pInstr.
//
// PSEUDOCODE:
// Call the base class Copy() function and pass pInstr as the param
// Copy the mInteger data member of pInteger to this object's mInteger data member
// Call Encode() to encode the instruction
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::Copy(InstrTypeRI pInstr)
{
    InstrTypeR::Copy(pInstr);                               
    SetVariable(pInstr.GetVariable());
    Encode();
}

//--------------------------------------------------------------------------------------------------------------
// SetInteger()
//
// DESCRIPTION:
// mInteger mutator function.
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::SetInteger(Integer pInteger)
{
    mInteger = pInteger;
}

//==============================================================================================================
// PRIVATE FUNCTION MEMBERS
//==============================================================================================================
